package com.txm.activityMQ;

import com.txm.model.hibernate.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.jms.*;

/*@Component*/
public class Producer {
    @Autowired
    private JmsTemplate jmsTemplate;
   /* @Autowired
    private MQMessageConverter mQMessageConverter;*/
    @Autowired
    @Qualifier("notifyQueue")
    private Destination destination;

    /*    public void sendMessages() {
            jmsTemplate.send(new MessageCreator() {
                public Message createMessage(Session session) throws JMSException {
                    return session.createTextMessage("dfdf");
                }
            });
        }*/
    public void sendMessage(final User bus) {
        jmsTemplate.send(destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                ObjectMessage objectMessage = session.createObjectMessage(bus);
                return objectMessage;
            }
        });
    }

}
